/**
 * 
 */
package common;

import model.Item;

/**
 *This class is used to generate messages that will be displayed on the map panel HUD.
 *
 */
public class MessageFactory {
	
	public static final String GAME_OVER_MESSAGE = "The Zombosaurs have overrun your space ship! None survived...";
	public static final String WELCOME_MESSAGE = "<html>                Welcome to Zombosaur Defence! <br><br>Protect your spaceship from the hordes of enemy Zombosaurs <br>with the items you can buy at the store</html>";
	
	public static String getItemDescription(Item item){
		String newLine = "<br>";
		
		String description = "<html>"+item.getName()+newLine+
								"     Cost: $"+item.getCost()+newLine+newLine+"     "+
								splitStringIntoLines(item.getDescription())+newLine+newLine+
								splitStringIntoLines(item.getUsageDescription())+"</html>";
		return description;
		
	}
	
	/**
	 * Using the < br > html tag, this function splits the String "original"
	 * into properly sized lines to be displayed in the message.
	 *
	 * @param original
	 * @return
	 */
	public static String splitStringIntoLines(String original){
		if(original == null)return " ";
		int charCount = 0;
		for(int i = 0; i < original.length(); i++){
			if(original.charAt(i) != ' ') charCount++;
			else if(original.charAt(i) == ' ' && charCount >= 35){
				charCount = 0;
				original = original.substring(0, i) + "<br>" + original.substring(i+1);
			}
		}
		return original;
	}

}
